package me.grm.cs.factory;

import java.lang.reflect.InvocationTargetException;
import me.grm.cs.course.CourseInfo;
import me.grm.cs.course.CoursePublic;
import me.grm.cs.course.ICourse;
import me.grm.cs.database.IDatabase;
import me.grm.cs.database.TextDatabase;


public class undergradCourseFactory implements ICourseFactory {
  public ICourse selectCourse(int index) {
    IDatabase database = TextDatabase.getInstance();
    CourseInfo courseInfo = database.getCourseInfo(index);
    try {
      Class cls = Class.forName(courseInfo.className);
      return (ICourse) cls.getConstructors()[0].newInstance(
          courseInfo.id, courseInfo.name, courseInfo.className);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
        | InvocationTargetException e) {
      e.printStackTrace();
    }

    return null;
  }
}
